package com.pkk.penguin.components.validator.annotation.constraint;

import com.pkk.components.util.enums.DigitalTypeEnum;
import com.pkk.penguin.components.validator.annotation.DigitalType;
import com.pkk.penguin.components.validator.util.RegularValidatorUtil;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: 数字类型验证
 * @author: luffy
 * @create: 2018-07-20 15:23
 **/
@Slf4j
public class DigitalValidator implements ConstraintValidator<DigitalType, String> {

  private DigitalTypeEnum formatUnit;

  @Override
  public void initialize(DigitalType interf) {
    this.formatUnit = interf.formatUnit();
  }

  @Override
  public boolean isValid(String field, ConstraintValidatorContext cxt) {
    return RegularValidatorUtil.isValid(formatUnit, field);
  }
}
